#  -*- coding: UTF-8 -*-
import threading
import threading
import time
import queue
# 多进程模式；
# 多线程模式；
# 多进程+多线程模式。
# 为线程定义一个函数
# def print_time(threadName,delay):
#     count =0
#     while count < 5:
#         time.sleep(delay)
#         count += 1
#         print "%s:%s" % (threadName,time.ctime(time.time()))
#         print "_______________"
#         print '\n'
# try:
#     thread.start_new_thread(print_time,("Thread-1",0))
#     thread.start_new_thread(print_time,("Thread-2",2))
#     # thread.start_new_thread(print_time,("Thread-3",6))
# except:
#     print 'error:unable to start thread'
# while 1:
#     pass

# exitFlag = 0
# class myThread(threading.Thread):  # 继承父类threading.Thread
#     def __init__(self, threadID, name, counter):
#         threading.Thread.__init__(self)
#         self.threadID = threadID
#         self.name = name
#         self.counter = counter
#     def run(self):  # 把要执行的代码写到run函数里面 线程在创建后会直接运行run函数
#         print "Starting " + self.name
#         print_time(self.name, self.counter, 5)
#         print "Exiting " + self.name
# def print_time(threadName, delay, counter):
#     while counter:
#         if exitFlag:
#             (threading.Thread).exit()
#         time.sleep(delay)
#         print "%s: %s" % (threadName, time.ctime(time.time()))
#         counter -= 1
# # 创建新线程
# thread1 = myThread(1, "Thread-1", 1)
# thread2 = myThread(2, "Thread-2", 2)
# # 开启线程
# thread1.start()
# thread2.start()
# print "Exiting Main Thread"

# class myThread(threading.Thread):
#     def __init__(self,threadID, name, counter):
#         threading.Thread.__init__(self)
#         self.threadID = threadID
#         self.name = name
#         self.counter = counter
#     def run(self):
#         print "Staring" + self.name
#         threadlock.acquire()
#         print_time(self.name,self.counter,4)
#         threadlock.release()
# def print_time(threadName,delay,counter):
#     while counter:
#         time.sleep(delay)
#         print '%s :%s' % (threadName,time.ctime(time.time()))
#         counter -= 1
# threadlock = threading.Lock()
# threads = []
# thread1 = myThread(1,'Thread-1',1)
# thread2 = myThread(2,'Thread-2',2)
# thread1.start()
# thread2.start()
# threads.append(thread1)
# threads.append(thread2)
# for i in threads:
#     i.join()
# print 'Exting Main Thread'

# from threading import Thread ,Lock,RLock
# class myThread(threading.Thread):
#     def __init__(self,threadID, name, counter):
#         threading.Thread.__init__(self)
#         self.threadID = threadID
#         self.name = name
#         self.counter = counter
#     def run(self):
#         lock.acquire()
#         print "Staring" + self.name
#         print_time(self.name,self.counter,4)
#         lock.release()
# def print_time(threadName,delay,counter):
#     while counter:
#         time.sleep(delay)
#         print '%s :%s' % (threadName,time.ctime(time.time()))
#         counter -= 1
# lock = RLock()
# threads = []
# thread1 = myThread(1,'Thread-1',1)
# thread2 = myThread(2,'Thread-2',2)
# thread1.start()
# thread2.start()
# threads.append(thread1)
# threads.append(thread2)
# for i in threads:
#     i.join()
# print 'Exting Main Thread'




def show(q, i):
    if q.empty() or q.qsize() >= 1:
        q.put(i)  # 存队列
    elif q.full():
        print('queue not size')


que = queue.Queue(5)  # 允许5个队列的队列对象
for i in range(5):
    show(que, i)
print('queue is number:', que.qsize())  # 队列元素个数
for j in range(5):
    print(que.get())  # 取队列
print('......end')